import json
import time
import random

import xlrd
import redis
import requests
from flask import Flask,request
from flask_cors import CORS

import color_convert

class my_color:
    def __init__(self, color_class, color_rgb):
        self.color_class = color_class
        self.rgb = color_rgb
        self.hex = color_convert.rgb_convert_hexstring(self.rgb)

    def __repr__(self) -> str:
        return (
            "class:{}, rgb:{}, hex:{}"
            .format(
                self.color_class,
                self.rgb,
                self.hex,
            ))

# class my_color_encoder(json.JSONEncoder):
#     def default(self, obj):
#         if isinstance(obj, my_color):
#             return {
#                 'class': obj.color_class,
#                 'rgb': obj.rgb,
#             }
#         return json.JSONEncoder.default(self, obj)

# def my_color_decoder(obj):
#     if isinstance(obj, dict):
#         if 'class' in obj.keys():
#             if 'rgb' in obj.keys():
#                 return my_color(obj['class'], obj['rgb'])
#     return obj



# flask
app = Flask(__name__)
CORS(app, supports_credentials=True)

# redis connect
redis_conn = redis.Redis(host='127.0.0.1', port=6379, decode_responses=True)

# all_color_config table
all_color_config = {}
background_config = {}
all_color_list = [] # 颜色列表
all_color_list_back = []
background_list = []

title_front_color_list = ["#ffffff", "#000000"] # 程序定义
neutral_color_list = ["#ffffff", "#000000"] # 中和颜色


# 解析所有颜色 分类存
def parse_color_table(excel_all_color_sheet):
    all_class_color = {}
    nrow = excel_all_color_sheet.nrows
    for i in range(nrow):
        if i < 2:
            continue
        color_desc = excel_all_color_sheet.cell_value(i, 0)
        color_class = int(excel_all_color_sheet.cell_value(i, 1))
        color_l = int(excel_all_color_sheet.cell_value(i, 2))
        color_a = int(excel_all_color_sheet.cell_value(i, 3))
        color_b = int(excel_all_color_sheet.cell_value(i, 4))
        color_R = int(excel_all_color_sheet.cell_value(i, 6))
        color_G = int(excel_all_color_sheet.cell_value(i, 7))
        color_B = int(excel_all_color_sheet.cell_value(i, 8))
        rgb = ((color_R << 16) | (color_G << 8) | color_B)
        color_item = my_color(color_class, rgb)
        if color_class in all_class_color.keys():
            all_class_color[color_class].append(color_item)
        else:
            all_class_color[color_class] = [color_item]
    return all_class_color


def parse_color_config_table():
    global all_color_config
    global background_config
    global all_color_list
    global all_color_list_back
    global background_list

    color_lab_config_path = "./lab_color_config.xls"
    ef = xlrd.open_workbook(color_lab_config_path)
    all_color_sheet = ef.sheet_by_name("all_color")
    backgroud_sheet = ef.sheet_by_name("background")
    temp_front_color_sheet = ef.sheet_by_name("title_front_color")
    all_color_config = parse_color_table(all_color_sheet)
    background_config = parse_color_table(backgroud_sheet)
    for k, v in all_color_config.items():
        list_len = len(v)
        for item in v:
            all_color_list.append(item)
            all_color_list_back.append(item)
    for k, v in background_config.items():
        list_len = len(v)
        for item in v:
            background_list.append(item)
    return


# 用户初始化
def user_init(uid):
    seq = []
    l_bg_color_list = background_list
    l_color_list = all_color_list
    # 洗牌
    random.shuffle(l_color_list)
    n1 = len(l_color_list)
    n2 = len(l_bg_color_list)

    # print(l_bg_color_list)
    # print(title_front_color_list)

    seq_item = {}
    seq_item_list = []
    seq_item_list_00 = []  # 序列列表
    seq_item_list_01 = []  # 序列列表
    seq = {}
    index = 1
    key = "user:seq:" + str(uid)
    # 生成序列 目前应该有48种
    for i in range(0, n1):
        for j in range(0, n2):
            seq_item = {}
            seq_item["bg_color_class"] = l_bg_color_list[j].color_class
            seq_item["bg_color"] = l_bg_color_list[j].hex
            seq_item["t_color_class"] = l_color_list[i].color_class
            seq_item["t_color"] = l_color_list[i].hex
            seq_item["front_color"] = title_front_color_list[(j + 1) % n2]
            seq_item["neutral_color"] = neutral_color_list[j % n2]
            if 0 == j:
                seq_item_list_00.append(seq_item)
            if 1 == j:
                seq_item_list_01.append(seq_item)
    # 多洗两把牌
    random.shuffle(seq_item_list_00)
    random.shuffle(seq_item_list_01)
    random.shuffle(seq_item_list_00)
    random.shuffle(seq_item_list_01)

    for u0 in seq_item_list_00:
        seq_item_list.append(u0)
    for u1 in seq_item_list_01:
        seq_item_list.append(u1)
    
    # len01 = len(seq_item_list_01)
    # l01_i = 0
    # for u0 in seq_item_list_00:
    #     seq_item_list.append(u0)
    #     if l01_i < len01:
    #         seq_item_list.append(seq_item_list_01[l01_i])
    #         l01_i = l01_i + 1

    # print(len(seq_item_list))
    # 
    for item in seq_item_list:
        field = str(index)
        v = json.dumps(item)
        index = index + 1
        redis_conn.hset(key, field, v)

    # 初始化轮数量,组数
    key = "user:config:" + str(uid)
    uc = {}
    uc["curr_round"] = 1    # 当前进行的轮数
    uc["max_round"] = 4     # 最大进行4轮
    uc["curr_group"] = 1    # 当前进行的组数
    uc["max_group"] = 6     # 每轮最大6组
    uc["mode"] = 0          # 模式

    # 存redis
    for k,v in uc.items():
        redis_conn.hset(key, k, v)

    # 重置用户操作
    key = "user:operator:" + str(uid)
    redis_conn.delete(key)

    return seq


# 取当前进行的步骤
def fetch_step(uid):
    key = "user:config:" + str(uid)
    uc = redis_conn.hgetall(key)
    return uc

# 是否完成所有步骤
def is_fini_all_step(uid):
    uc = fetch_step(uid)
    cr = uc["curr_round"]
    cr = int(cr)
    mr = uc["max_round"]
    mr = int(mr)
    cg = uc["curr_group"]
    cg = int(cg)
    mg = uc["max_group"]
    mg = int(mg)
    m = uc["mode"]
    m = int(m)
    
    if mr == cr and mg == cg and m == 1:
        return True
    return False


# 取序列项
def fetch_seq_item(uid, round, group, mode):
    key = "user:seq:" + str(uid)
    field = (round - 1) * 6 * 2 + (group - 1) * 2 + 1 + mode
    v = redis_conn.hget(key, str(field))
    zv = json.loads(v)
    return zv

# 索引
def value_round_group_mode(round, group, mode):
    return (round - 1) * 6 * 2 + (group - 1) * 2 + 1 + mode

# 在当前看来，下一个实验是否是下一个组的
def next_lab_is_next_group(round, group, mode):
    r = round
    g = group
    m = mode
    m = m + 1
    if (m > 1):
        g = g + 1
    if (g > 6):
        return True
    return False

# 轮组模式加加
def add_count(uid, round, group, mode):
    key = "user:config:" + str(uid)
    r = round
    g = group
    m = mode
    m = m + 1
    if (m > 1):
        m = 0
        g = g + 1
    if (g > 6):
        g = 1
        r = r + 1
    uc = {}
    uc["curr_round"] = r    # 当前进行的轮数
    uc["curr_group"] = g    # 当前进行的组数
    uc["mode"] = m          # 模式
    # 存redis
    for k,v in uc.items():
        redis_conn.hset(key, k, v)
    return

# 取当前的模式
def get_curr_select_mode(uid):
    key = "user:operator:" + str(uid)
    field = "op_select_mode"
    v = redis_conn.hget(key, field)
    select_mode = None
    if None != v:
        zv = json.loads(v)
        select_mode = zv["select_mode"]
    return select_mode


# 客户端请求准备页面数据
@app.route('/page_ready', methods=['GET'])
def page_ready():
    # 取用户id
    uid = request.headers.get("uid")
    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)
    # 取序列
    seq_item = fetch_seq_item(uid, r, g, m)
    # tips
    tips = "准备进行第" + str(r) + "轮, 第" + str(g) + "组!"
    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)
    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "page_ready_" + str(index)
    value = {}
    value["time_ms"] = time_ms
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    rs["bg_color"] = seq_item["bg_color"]
    rs["front_color"] = seq_item["front_color"]
    rs["title"] = "实验说明" + str(r) + "-" + str(g)
    rs["desc_text"] = "在您阅读完此说明后点击“我已准备”，首先会出现一个十字架，这是进行眼校准，您无需操作，1s后会自动出现一个带有颜色的色块即目标色块。您需记住该目标色块的颜色，5s后会出现一个不同颜色组合的4x6排列的界面，您需在该界面中找到目标色块并点击，接着会出现一个灰色界面，这是中和颜色，您也无需操作，1s后会出现一个色块，您需判断该色块与之前的目标色块是否是一个颜色，是点击“Yes”，否点击“No”。"
    rs["button_text"] = "我已准备"
    rs["tips"] = tips
    proto_rs["data"] = [rs]
    return proto_rs


# 客户端请求校准页面数据
@app.route('/page_eye_calibration', methods=['GET'])
def page_eye_calibration():
    # 取用户id
    uid = request.headers.get("uid")
    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)
    # 取序列
    seq_item = fetch_seq_item(uid, r, g, m)

    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)

    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "page_eye_calibration_" + str(index)
    value = {}
    value["time_ms"] = time_ms
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    rs["title"] = "校准" + str(r) + "-" + str(g)
    rs["bg_color"] = seq_item["bg_color"]
    rs["front_color"] = seq_item["front_color"]
    proto_rs["data"] = [rs]
    return proto_rs 


# 客户端请求显示目标颜色页面数据
@app.route('/page_show_target_color', methods=['GET'])
def page_show_target_color():
    # 取用户id
    uid = request.headers.get("uid")
    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)
    # 取序列
    seq_item = fetch_seq_item(uid, r, g, m)

    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)

    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "page_show_target_color_" + str(index)
    value = {}
    value["time_ms"] = time_ms
    value["t_color_class"] = seq_item["t_color_class"]
    value["t_color"] = seq_item["t_color"]
    value["bg_color"] = seq_item["bg_color"]
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)

    # print(seq_item)

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    rs["title"] = "目标颜色" + str(r) + "-" + str(g)
    rs["bg_color"] = seq_item["bg_color"]
    rs["front_color"] = seq_item["front_color"]
    rs["t_color"] = seq_item["t_color"]
    rs["t_color_class"] = seq_item["t_color_class"]
    proto_rs["data"] = [rs]
    return proto_rs


# 客户端请求显示目标颜色页面数据
@app.route('/page_rand_color_set', methods=['GET'])
def page_rand_color_set():
    # 取用户id
    uid = request.headers.get("uid")
    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    # print(config)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)
    # 取序列
    seq_item = fetch_seq_item(uid, r, g, m)

    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)


    # 读取配表中的所有颜色返回
    op_table = []
    color_item = {}
    color_list = []
    random.shuffle(all_color_list)  # 先洗牌
    for item in all_color_list:
        color_item = {}
        color_item["color"] = item.hex
        color_item["color_class"] = item.color_class
        op_table.append(item.rgb)
        color_list.append(color_item)

    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "page_rand_color_set_" + str(index)
    value = {}
    value["time_ms"] = time_ms
    value["cp"] = json.dumps(op_table)
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)


    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    rs["title"] = "颜色池" + str(r) + "-" + str(g)
    rs["bg_color"] = seq_item["bg_color"]
    rs["front_color"] = seq_item["front_color"]
    rs["box_color_list"] = color_list
    proto_rs["data"] = [rs]

    # print(" index = " + str(index) + "  bg_color = " + seq_item["bg_color"])
    return proto_rs


# 客户端请求显示目标颜色页面数据
@app.route('/page_test_color', methods=['GET'])
def page_test_color():
    # 取用户id
    uid = request.headers.get("uid")
    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)
    # 取序列
    seq_item = fetch_seq_item(uid, r, g, m)
    # 取序列中的目标颜色类型
    t_color_class = seq_item["t_color_class"]

    # 从色系中选择一个颜色
    test_class_color = 0
    class_color_list = all_color_config[t_color_class]
    class_color_list_len = len(class_color_list)
    test_index = random.randint(0, class_color_list_len - 1)
    test_class_color = class_color_list[test_index].hex
    test_class_color_class = class_color_list[test_index].color_class

    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)

    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "page_test_color_" + str(index)
    value = {}
    value["time_ms"] = time_ms
    value["color"] = test_class_color
    value["color_class"] = test_class_color_class
    value["bg_color"] = seq_item["bg_color"]
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    rs["bg_color"] = seq_item["bg_color"]
    rs["front_color"] = seq_item["front_color"]
    rs["title"] = "测试" + str(r) + "-" + str(g)
    rs["box_color"] = test_class_color
    rs["box_color_class"] = test_class_color_class
    rs["yes_button_desc"] = "yes"
    rs["no_button_desc"] = "no"
    proto_rs["data"] = [rs]
    return proto_rs


# 客户端请求显示目标颜色页面数据
@app.route('/page_fini', methods=['GET'])
def page_fini():
    # 取用户id
    uid = request.headers.get("uid")
    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)
    # 取序列
    seq_item = fetch_seq_item(uid, r, g, m)

    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)
    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "page_fini_" + str(index)
    value = {}
    value["time_ms"] = time_ms
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)

    over = 0
    timer = 2000
    desc = "请等待2s进入下一个实验"
    show_task_desc = 0
    # 最后一个页面, 检查是否结束
    if is_fini_all_step(uid):
        over = 1
        timer = 5000
        desc = "实验完成, 已保存本次实验数据，谢谢!，稍等5s会重新进入实验"
        async_push_user_op(uid)
        user_init(uid)
    else:
        # 检查下一个实验是否是下一组
        # print("next: = " + " r = " + str(r) + " g = " + str(g) + " m = " + str(m))
        if next_lab_is_next_group(r, g, m):
            show_task_desc = 1
            desc = "请等待2s进入下一组的实验"

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    rs["bg_color"] = seq_item["bg_color"]
    rs["front_color"] = seq_item["front_color"]
    rs["title"] = "总结" + str(r) + "-" + str(g)
    rs["over"] = over
    rs["timer"] = timer
    rs["desc"] = desc
    rs["show_task_desc"] = show_task_desc
    proto_rs["data"] = [rs]
    return proto_rs



#############模式切换请求-begin#################
#模式切换 请求, 进入下一个实验倒计时到期发送请求
@app.route('/mode_change', methods=['GET'])
def mode_change():
    # 取用户id
    uid = request.headers.get("uid")
    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)
    # # 取序列
    # seq_item = fetch_seq_item(uid, r, g, m)

    # 增加计数
    add_count(uid, r, g, m)

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    #
    rs = {}
    rs["uid"] = uid
    proto_rs["data"] = [rs]
    return proto_rs

# 用户登陆
@app.route('/wechat_login', methods=['POST'])
def wechat_login():
    index_desc = 'Welcome!'
    is_over = False
    # 0 跳转到选择模式
    # 1 跳转至任务描述
    code = 0

    r_json = request.get_json()
    wechat_code = r_json.get('code')
    wechat_app_id = 'wx861790198a8e0309'
    wechat_app_secret = '8bd719e12db7e700f04dceb128c39e7a'
    
    # 取用户id
    url = f'https://api.weixin.qq.com/sns/jscode2session?appid={wechat_app_id}&secret={wechat_app_secret}&js_code={wechat_code}&grant_type=authorization_code'
    res = requests.get(url)
    openid = res.json().get('openid')
    uid = openid
    
    key = "user:config:" + str(uid)
    uc = redis_conn.hgetall(key)
    if uc == {}:
        user_init(uid)
        code = 0
        index_desc = "欢迎! 准备开始实验"

    # 最后一个页面, 检查是否结束
    if is_fini_all_step(uid):
        is_over = True
        code = 0
        index_desc = "您已完成实验, 非常感谢您的参与, 谢谢!"
    else:
        # 检查否是选择过模式
        if get_curr_select_mode(uid) != None: # 选择过
            index_desc = "准备继续之前的实验"
            code = 1
        else:   # 没有选择过
            index_desc = "准备开始实验"
            code = 0


    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs['msg'] = 'ok'
    rs['uid'] = uid
    rs['openid'] = openid
    rs['index_desc'] = index_desc
    rs['is_over'] = is_over
    rs['code'] = code
    proto_rs['data'] = rs

    # print(rs)
    return proto_rs


# 用户最终确认是否是目标颜色
@app.route('/op_ack_color', methods=['GET'])
def op_ack_color():
    # 取用户id， 用户操作
    uid = request.headers.get("uid")
    ack = request.headers.get("ack")

    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)

    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)

    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "op_ack_color_" + str(index)
    value = {}
    value["time_ms"] = time_ms
    value["ack"] = ack
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    proto_rs["data"] = [rs]
    return proto_rs


# 用户选择的模式
@app.route('/op_select_mode', methods=['GET'])
def op_select_mode():
    # 取用户id， 用户操作
    uid = request.headers.get("uid")
    select_mode = request.headers.get("select_mode")

    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)

    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "op_select_mode"
    value = {}
    value["time_ms"] = time_ms
    value["select_mode"] = str(select_mode)
    print("select_mode = " + str(select_mode))
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    proto_rs["data"] = [rs]
    return proto_rs



# 用户选择的模式
@app.route('/op_err_select', methods=['GET'])
def op_err_select():
    # 取用户id， 用户操作
    uid = request.headers.get("uid")
    err_list = request.headers.get("err_list")
    print(json.loads(err_list))

    # 取当前进行的轮数和组数以及模式
    config = fetch_step(uid)
    r = config["curr_round"]    # 进行的轮数
    g = config["curr_group"]    # 进行的组数
    m = config["mode"]          # 进行的模式
    r = int(r)
    g = int(g)
    m = int(m)
    # 索引
    index = value_round_group_mode(r, g, m)

    # 当前毫秒时间
    t = time.time()
    time_ms = round(t * 1000)

    # 记录用户操作
    key = "user:operator:" + str(uid)
    filed = "op_err_select_" + str(index)

    value = {}
    value["time_ms"] = time_ms
    value["err_list"] = err_list
    expire = 60 * 60 * 2  # 2h 后过期
    redis_conn.hset(key, filed, json.dumps(value))
    redis_conn.expire(key, expire)

    # 回包
    proto_rs = {}
    proto_rs["code"] = 0
    rs = {}
    rs["uid"] = uid
    proto_rs["data"] = [rs]
    return proto_rs


#############模式切换请求-end#################

# 写数据
def async_push_user_op(uid):
    key = "user:operator:" + str(uid)
    uc = redis_conn.hgetall(key)
    uc["uid"] = str(uid)
    str_json = json.dumps(uc)
    key = "queue:user:op"
    redis_conn.lpush(key, str_json)



# 解析配表
parse_color_config_table()


app.run(port=6000)
